"""
用户登录度小满家庭记账系统（管理员账户：admin/123456,普通用户:lisi/123456），
若满足三次之内登录成功,进度进入家庭记账界面。若管理登录成功，可对用户的日常理财流程进行打印。
"""
from Account import Account

# 登录模块
user = {'admin': '123456', 'lisi': '123456'}
accounts = []
balance = 0
i = 0

while True:
    username = input('请输入用户名: ')
    password = input('请输入密码: ')
    if username in user.keys() and password == user[username]:
        i = 0
        print('登录成功')
        # 判断用户身份 选择功能模块
        while True:
            if username == 'admin':
                print('1. 添加账务   2. 编辑账务  3. 删除账务  4. 查询账务  5. 退出系统')
                opt = int(input('请选择功能模块编号：'))
            else:
                opt = 4
            # 添加账务
            if opt == 1:
                category = input('账务类型： 1. 支出  2. 收入')
                account = input('账户：')
                money = int(input('钱款：'))
                comment = input('账单备注: ')
                if category == '1':
                    record, balance = Account.expend(account, money, balance, comment)
                    accounts.append(record)
                if category == '2':
                    record, balance = Account.income(account, money, balance, comment)
                    accounts.append(record)
            # 编辑账务
            elif opt == 2:
                index = int(input('请输入要修改的记录id')) - 1
                if len(accounts) > index >= 0:
                    accounts[index].comment = input('请输入备注：')
                else:
                    print('输入非法')
            # 删除账务
            elif opt == 3:
                index = int(input('请输入要删除的记录id')) - 1
                if len(accounts) > index >= 0:
                    print('删除成功')
                    del accounts[index]
                else:
                    print('输入非法')
            # 查询系统
            elif opt == 4:
                print('ID\t类型\t\t账户\t\t金额\t\t余额\t\t时间\t\t备注')
                for index, account in enumerate(accounts):
                    print('%s\t%s\t%s\t%s\t%s\t%s\t%s\t' % (
                        index + 1, account.category, account.account, account.money, account.balance, account.time,
                        account.comment))
            # 退出系统
            elif opt == 5:
                print('5')
                break
            input('输入任意键以继续...\n')
    else:
        i += 1
        print('账号或密码错误，请重试')
        print('已尝试：%s' % i)
        if i == 3:
            break
